<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>Hexo 博客搭建折腾记录 | ZHB&#39;s Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="记录自己搭建本博客的过程。">
<meta name="keywords" content="Blog">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo 博客搭建折腾记录">
<meta property="og:url" content="https://gkzhb.github.io/2019/01/hexo/index.html">
<meta property="og:site_name" content="ZHB&#39;s Blog">
<meta property="og:description" content="记录自己搭建本博客的过程。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-06-23T10:14:28.695Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hexo 博客搭建折腾记录">
<meta name="twitter:description" content="记录自己搭建本博客的过程。">
  
    <link rel="alternate" href="/atom.xml" title="ZHB&#39;s Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link rel="stylesheet" href="/css/sourcecodepro.css">
    <!-- <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css"> -->
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">ZHB&#39;s Blog</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://gkzhb.github.io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-hexo" class="article article-type-post" itemscope itemprop="blogPost">



  <div class="article-meta">
    <a href="/2019/01/hexo/" class="article-date">
  <time datetime="2019-01-01T13:35:16.000Z" itemprop="datePublished">2019-01-01</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Self-hosting/">Self-hosting</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Hexo 博客搭建折腾记录
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
		<!-- Table of Contents -->
		
			<div id="toc" class="toc-article">
				<strong class="toc-title">Table of Content</strong>
				<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#在-hexo-中使用-latex-渲染数学公式"><span class="toc-number">1.</span> <span class="toc-text">在 Hexo 中使用 LaTeX 渲染数学公式</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#步骤"><span class="toc-number">1.1.</span> <span class="toc-text">步骤</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#安装-pandoc-和-hexo-render-pandoc"><span class="toc-number">1.1.1.</span> <span class="toc-text">安装 pandoc 和 hexo-render-pandoc</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#停止使用-hexo-math并安装-mathjax-包"><span class="toc-number">1.1.2.</span> <span class="toc-text">停止使用 hexo-math，并安装 Mathjax 包</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#更新-mathjax-的配置文件"><span class="toc-number">1.1.3.</span> <span class="toc-text">更新 Mathjax 的配置文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#开启-mathjax"><span class="toc-number">1.1.4.</span> <span class="toc-text">开启 Mathjax</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#测试"><span class="toc-number">1.1.5.</span> <span class="toc-text">测试</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#更新"><span class="toc-number">2.</span> <span class="toc-text">更新</span></a></li></ol>
			</div>
		
        <p>记录自己搭建本博客的过程。</p>
<a id="more"></a>
<h2 id="在-hexo-中使用-latex-渲染数学公式">在 Hexo 中使用 LaTeX 渲染数学公式</h2>
<p>参考：</p>
<ul>
<li><a href="https://blog.csdn.net/Aoman_Hao/article/details/81381507" target="_blank" rel="noopener">使用LaTex添加公式到Hexo博客里 - Aoman_Hao的博客 - CSDN博客</a></li>
<li><a href="https://blog.csdn.net/crazy_scott/article/details/79293576" target="_blank" rel="noopener">hexo下LaTeX无法显示的解决方案 - crazy_scott的博客 - CSDN博客</a></li>
</ul>
<h3 id="步骤">步骤</h3>
<h4 id="安装-pandoc-和-hexo-render-pandoc">安装 pandoc 和 hexo-render-pandoc</h4>
<p>将 Hexo 默认渲染引擎 marked (不支持 Mathjax) 更换为 hexo-renderer-pandoc 引擎 (支持 Mathjax 公式输出)，这个引擎需要安装 pandoc （一个提供各种文档格式转化的工具）</p>
<p>在 Hexo 目录下，输入下面的命令卸载默认渲染引擎，安装新的引擎： <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ npm uninstall hexo-renderer-marked --save</span><br><span class="line">$ npm install hexo-renderer-pandoc --save</span><br></pre></td></tr></table></figure></p>
<p>如果在生成网页的时候 pandoc 有关于 smart 的报错，将 <code>node_modules/hexo-renderer-pandoc/index.js</code> 文件中所有的 <code>-smart</code> 删掉即可。</p>
<h4 id="停止使用-hexo-math并安装-mathjax-包">停止使用 hexo-math，并安装 Mathjax 包</h4>
<p>卸载 hexo-math： <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm uninstall hexo-math --save</span><br></pre></td></tr></table></figure></p>
<p>安装 hexo-renderer-mathjax 包： <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install hexo-renderer-mathjax --save</span><br></pre></td></tr></table></figure></p>
<h4 id="更新-mathjax-的配置文件">更新 Mathjax 的配置文件</h4>
<p>打开 <code>node_modules/hexo-renderer-mathjax/mathjax.html</code>，将最后一行 <code>&lt;script  src="..."&gt;&lt;/script&gt;</code> 内容注释掉，加上以下内容： <figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>或者将 <a href="https://github.com/mathjax/mathjax" target="_blank" rel="noopener">Mathjax</a> 源文件下载解压到 source 目录下，将上面的网址改为 <code>/mathjax/MathJax.js?config=TeX-MML-AM_CHTML</code> （注意 <code>MathJax.js</code> 文件路径要对应上网址）。</p>
<p>再在 <code>MathJax.Hub.Config({</code> 下添加两行内容： <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">messageStyle: <span class="string">"none"</span>,</span><br><span class="line">showProcessingMessages: <span class="literal">false</span>,</span><br></pre></td></tr></table></figure></p>
<h4 id="开启-mathjax">开启 Mathjax</h4>
<p>在 <code>themes/[Your Theme]/config.yml</code> 中，添加如下代码 (如果存在 <code>mathjax:</code> 就不用添加这一行了) <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mathjax:</span><br><span class="line">	enable: true</span><br></pre></td></tr></table></figure></p>
<p>或者 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mathjax: true</span><br></pre></td></tr></table></figure></p>
<p><strong>注意配置项和参数中间有一个空格不能漏掉</strong></p>
<p>写博客 posts 时，要开启 <code>Mathjax</code> 选项，即在文章的 Front-matter 里添加以下内容（我没有添加这一项也成功渲染出来了）： <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mathjax: true</span><br></pre></td></tr></table></figure></p>
<p>例如： <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: hexo</span><br><span class="line">date: 2019-1-1</span><br><span class="line">tags:</span><br><span class="line">mathjax: true</span><br><span class="line">---</span><br></pre></td></tr></table></figure></p>
<h4 id="测试">测试</h4>
<p>添加一段 LaTeX 代码： <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$$lim_&#123;1\to+\infty&#125;P(|\frac&#123;1&#125;&#123;n&#125;\sum_i^nX_i-\mu|&lt;\epsilon)=1,\ i=1,...,\ n$$</span><br></pre></td></tr></table></figure></p>
<p>渲染结果如下： <span class="math display">\[lim_{1\to+\infty}P(|\frac{1}{n}\sum_i^nX_i-\mu|&lt;\epsilon)=1,\ i=1,\ ...,\ n\]</span></p>
<!-- ## 使用七牛云加速网站资源的加载 (无法长期使用，放弃)

考虑到 Github 网速较慢，加载网页图片等速度较慢。我选择国内的 CDN 服务运营商七牛云来加速网站加载。

### 使用插件 [hexo-qiniu-sync](https://github.com/gyk001/hexo-qiniu-sync)

1. 根据插件的 `README` 操作，用 `npm install hexo-qiniu-sync --save` 命令安装插件
1. 在 `_config.yml` 文件中，根据提示修改。主要修改的地方有几个：
    * `bucket` - 改为自己的空间名称
    * `access_key` `secret_key` - 在七牛云中点击个人面板，密钥管理中有这两个参数，**注意不要泄漏这些密钥**！ (如果仓库是公开的话，可以修改 `secret_file` 参数，将密钥放在本地文件中而不在此处添加密钥，并将这个文件添加到 `.gitignore` 中)
    * `urlPrefix` - 修改为自己存储空间的域名 (注意 `.com/` 后面的部分要与 `dirPrefix` 的内容保持一致)
1. 设置完成后，执行 `hexo g` 就会自动生成一个 `local_dir` 对应的目录，在其中对应目录下存放对应文件即可
1. 使用命令 `hexo s` 会自动上传同步 `local_dir` 中的文件
**不知为何我一直无法成功上传**，两个 key 也检查过没有错误。
```
ERROR get file stat err: static/images/xxx.jpeg
[object Object]
``` -->
<h2 id="更新">更新</h2>
<ul>
<li>最后更新于 2019-06-23</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://gkzhb.github.io/2019/01/hexo/" data-id="cjx8rzvpe000r9jw8quqsldsc" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Blog/">Blog</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/02/sven/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          搭建 sven 服务器记录
        
      </div>
    </a>
  
  
    <a href="/2018/12/memory/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">改革开放 40 年回忆</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Landscape/">Landscape</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Linux/">Linux</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Programming/">Programming</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Self-hosting/">Self-hosting</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Software/">Software</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Anki/">Anki</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Blog/">Blog</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Command-Line/">Command Line</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Data-Structure/">Data Structure</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Games/">Games</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Hometown/">Hometown</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux/">Linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Network/">Network</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Read-It-Later/">Read-It-Later</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Recall/">Recall</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Regular-Expression/">Regular Expression</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Server/">Server</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Spring/">Spring</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/折腾/">折腾</a></li></ul>
    </div>
  </div>


  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 Haibin Zhang<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> -->

<!-- <script src="http://apps.bdimg.com/libs/jquery/2.0.3/jquery.min.js"></script> -->
<script src="/mathjax/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script src="/js/jquery.min.js"></script>

  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>




  </div>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
		messageStyle: "none",
		showProcessingMessages: false,
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<!-- <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -->
<script src="/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

</body>
</html>